package weaver.interfaces.wjutil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * JDBCUtil工具类
 * @author wangjiepc
 *
 */
public class JDBCUtils {

	//数据库驱动
	private String driverClassPath = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
	
	//数据库地址、用户名、密码
	private String databaseUrl = "dbc:sqlserver://localhost:1433;databaseName=ecology";
	private String userName = "sa";
	private String password = "sa";
	
	//连接对象
	private Connection conn = null;
	
	//构造方法
	public JDBCUtils(String DriverClassPath,String databaseUrl,String userName,String password){
		this.driverClassPath = DriverClassPath;
		this.databaseUrl = databaseUrl;
		this.userName = userName;
		this.password = password;
		
	}
	
	public JDBCUtils(String databaseUrl,String userName,String password){
		this.databaseUrl = databaseUrl;
		this.userName = userName;
		this.password = password;
		
	}
	
	public JDBCUtils(String userName,String password){
		this.userName = userName;
		this.password = password;
	}
	
	
	//初始化连接
	public JDBCUtils init() throws Exception{
		//加载驱动
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		//获取连接
		conn = DriverManager.getConnection(databaseUrl, userName, password);
		return this;
	}

	public String getDriverClassPath() {
		return driverClassPath;
	}

	public void setDriverClassPath(String driverClassPath) {
		this.driverClassPath = driverClassPath;
	}

	public String getDatabaseUrl() {
		return databaseUrl;
	}

	public void setDatabaseUrl(String databaseUrl) {
		this.databaseUrl = databaseUrl;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Connection getConn() {
		return conn;
	}

	public void setConn(Connection conn) {
		this.conn = conn;
	}
	
	
	
}
